package cn.ys.base.controller;

import cn.ys.base.service.VerifyCodeService;
import cn.ys.base.util.AjaxResult;
import cn.ys.org.dto.PhoneRegisterDto;
import cn.ys.org.dto.ShopUserCodeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService service;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {

        String imageCode = service.imageCode(imageCodeKey);
        return AjaxResult.me().success(imageCode);
    }

    // 手机号发送验证码
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid ShopUserCodeDto dto){

        service.smsCode(dto);
        return AjaxResult.me().success();
    }

    // 手机号注册
    @PostMapping("/phoneRegister")
    public AjaxResult phoneRegister(@RequestBody @Valid PhoneRegisterDto dto){

        service.phoneRegister(dto);
        return AjaxResult.me().success();
    }
}
